﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
     layui.use(['jquery', 'form', 'laydate', 'tableEdit', 'commonTable', 'table', 'common', 'optimizeSelectOption'], function () {
         var form = layui.form,
             $ = layui.$,
             laydate = layui.laydate,
             tableEdit = layui.tableEdit,
             table = layui.table,
             commonTable = layui.commonTable,
             common = layui.common;
         var keyValue = $.request("keyValue");

           var params = [];
          var listData = [];
         //权限字段
         common.authorizeFields('adminform');

         //此处需修改
         //类型为时间时
         laydate.render({
             elem: '#F_HeadDate'
             ,type:'month'
             , trigger: 'click',
             format: 'yyyy-MM',
         });

         $(function () {
             initControl();
             if (!!keyValue) {
                  common.ajax({
                     url: '/SalaryManagement/Salarytable/GetFormJson',
                    dataType: 'json',
                    data: { keyValue: keyValue },
                    async: false,
                    success: function (data) {
                        common.val('adminform', data);
                         if (!!data.list && data.list.length > 0) {
                             listData = data.list;
                         }
                          var now=new Date(data.F_HeadDate);
                          $('#F_HeadDate').val(now.getFullYear() + "-" +((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1));
                     }
                });
             } else {
                 var d=new Date();
                 $('#F_EnCode').val(d.formatDate('yyyyMMddhhmmss'));
                 //$('#F_HeadDate').val(d.getFullYear()+'-'+(d.getMonth()+1));
                     var now = new Date();
                     var time = now.getFullYear() + "-" +((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1);
            $('#F_HeadDate').val(time);
             }

            form.render();

             var cols = [[

                 { field: 'F_UserId', title: 'F_UserId',  minWidth:80 , sort: true, config: { type: 'signedInput' },hide:true},
                 { field: 'F_OrganizeId', title: '部门', minWidth: 80, sort: true, config: { type: 'signedInput' } },
                 { field: 'F_UserNum', title: '工号',  minWidth: 80, sort: true, config: { type: 'signedInput' } },
                 { field: 'F_RealName', title: '姓名', minWidth: 80, sort: true, config: { type: 'signedInput' } },
                 { field: 'F_JopName', title: '岗位', minWidth: 80, sort: true, config: { type: 'signedInput' } },


                 { field: 'BasicAmount', title: '基本工资', minWidth: 80, sort: true, config: { type: 'signedInput' }
                 , templet: function (d){
                   // 保留两位小数
                   return (d.BasicAmount|| 0).toFixed(2);
                 } },
                 { field: 'JopAmount', title: '岗位工资', minWidth: 80, sort: true, config: { type: 'signedInput' },
                 templet: function(d){
                   // 保留两位小数
                   return (d.JopAmount || 0).toFixed(2);
                 } },
                 { field: 'F_ComAgeSalary', title: '司龄工资', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_ComAgeSalary || 0).toFixed(2);
                 } },

                 { field: 'SkillsAmount', title: '技能工资', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.SkillsAmount || 0).toFixed(2);
                 } },
                  { field: 'F_PerformanceSalary', title: '绩效工资', minWidth: 80, sort: true, config: { type: 'signedInput' } ,templet: function(d){
                   // 保留两位小数
                   return (d.F_PerformanceSalary || 0).toFixed(2);
                 } },
                  { field: 'BenefitCoefficient', title: '效益系数', minWidth: 80, sort: true, config: { type: 'signedInput' }},
                 { field: 'F_BenefitSalary', title: '效益工资', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_BenefitSalary || 0).toFixed(2);
                 } },
                 { field: 'F_Times2', title: '加班', minWidth: 80, sort: true, config: { type: 'signedInput' }},
                 { field: 'F_Times3', title: '六日加班', minWidth: 80, sort: true, config: { type: 'signedInput' } },
                 { field: 'F_Times4', title: '法定假日加班', minWidth: 80, sort: true, config: { type: 'signedInput' } },

                 { field: 'F_TimesSalary', title: '加班工资',minWidth: 80, sort: true, config: { type: 'signedInput' } ,templet: function(d){
                   // 保留两位小数
                   return (d.F_TimesSalary || 0).toFixed(2);
                 } },
                 { field: 'F_NightShiftSalary', title: '夜班补助', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_NightShiftSalary || 0).toFixed(2);
                 }  },
                 { field: 'F_SubsidyAmount', title: '特殊补贴', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_SubsidyAmount || 0).toFixed(2);
                 }  },
                 { field: 'F_Holiday', title: '请假天', minWidth: 80, sort: true, config: { type: 'signedInput' } },
                 { field: 'F_HolidaySalary', title: '请假扣除', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_HolidaySalary || 0).toFixed(2);
                 } },
                 { field: 'F_WelfareSubsidy', title: '福利补贴', minWidth: 80, sort: true, config: { type: 'signedInput' }},
                 { field: 'F_WelfareSubsidySalary', title: '福利补贴金额',minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_WelfareSubsidySalary || 0).toFixed(2);
                 }  },
                 { field: 'F_Insurance', title: '五险', minWidth: 80, sort: true, config: { type: 'signedInput' }},
                 { field: 'F_InsuranceSalary', title: '五险金额', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_InsuranceSalary || 0).toFixed(2);
                 } },
                  { field: 'F_Provident', title: '公积金', minWidth: 80, sort: true, config: { type: 'signedInput' }},
                 { field: 'F_ProvidentSalary', title: '公积金金额', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_ProvidentSalary || 0).toFixed(2);
                 } },
                  { field: 'F_BigSickSalsry', title: '大病', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_BigSickSalsry || 0).toFixed(2);
                 } },
                 { field: 'F_AwardSalary', title: '奖励',minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_AwardSalary || 0).toFixed(2);
                 }  },
                 { field: 'F_YearEndBonusSalary', title: '奖金', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_YearEndBonusSalary || 0).toFixed(2);
                 }  },
                 { field: 'F_PunishmentSalary', title: '扣款',minWidth: 80, sort: true, config: { type: 'signedInput' } ,templet: function(d){
                   // 保留两位小数
                   return (d.F_PunishmentSalary || 0).toFixed(2);
                 } },

                 { field: 'F_TaxSalary', title: '个税', minWidth: 80, sort: true, config: { type: 'signedInput' },templet: function(d){
                   // 保留两位小数
                   return (d.F_TaxSalary || 0).toFixed(2);
                 }  },
                 { field: 'F_DeservedSalary', title: '应得工资', minWidth: 80, sort: true, config: { type: 'signedInput' } ,templet: function(d){
                   // 保留两位小数
                   return (d.F_DeservedSalary || 0).toFixed(2);
                 } },
                 { field: 'F_ReallySalary', title: '实得工资', minWidth: 80, sort: true, config: { type: 'signedInput' } ,templet: function(d){
                   // 保留两位小数
                   return (d.F_ReallySalary || 0).toFixed(2);
                 } },


             ]];
             commonTable.rendertable({
                 elem: '#currentTableId',
                 data: listData,
                 defaultToolbar: [],
                 search: false,
                 limit: 9999,//每页数据 默认
                 page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                     layout: ['count'] //自定义分页布局
                     , first: false //不显示首页
                     , last: false //不显示尾页
                 },
                 height: 'full-185',
                 filter: {
                     clearFilter: false,
                 },
                 cols: cols
             });

             var aopTable = tableEdit.aopObj(cols); //获取一个aop对象
             aopTable.on('tool(currentTableFilter)', function (obj) {
                 var field = obj.field; //单元格字段
                 var value = obj.value; //修改后的值
                 var data = obj.data; //当前行旧数据
                 var event = obj.event; //当前单元格事件属性值
                 var dataCache = obj.dataCache;// 得到当前行缓存数据
                 var tr = obj.tr; // 得到当前行 <tr> 元素的 jQuery 对象

                  var update = {};
                   // if (event === 'Shift') { //查看

                   //  update['F_Shift'] = value.value;


                   // }




                 update[field] = value;

                 //把value更新到行中
                 obj.update(update);
             });
             //行点击事件监听，控制按钮显示
             var oneList = [];//选择1条显示
             var moreList = ["NF-delete"];//多条显示
             commonTable.tableRowClick("checkbox", "currentTableFilter", "currentTableId", oneList, moreList);
        });
        wcLoading.close();
         table.on('toolbar(currentTableFilter)', function (obj) {
             var data = table.checkStatus('currentTableId').data;
             // if (obj.event === 'add') {  // 监听添加操作\
             //     var alldata = table.cache.currentTableId;
             //     alldata.push({ F_Id: uuid(), F_Datetime: new Date().formatDate('yyyy-MM-dd'), F_UserNum: '', F_RealName: '',  F_Times1: '0', F_Times2: '0', F_Times3: '0', F_Times4: '0', F_SubsidyAmount: '0' })
             //     table.reload('currentTableId', { data: alldata })
             //  }else

              if(obj.event === 'add') {
                 if ($('#F_HeadDate').val() =="") {
                     common.modalMsg("核算月不能为空！", "warning");
                     return false;
                 }
                  common.ajax({
                   url: '/SalaryManagement/Salarytable/CalculateWages',
                   dataType: 'json',
                   data: { keyword: $('#F_HeadDate').val() },
                   async: false,
                   success: function (data) {

                        if (!!data&& data.length > 0) {

         table.reload('currentTableId', { data: data });


                         }

                    }
               });

            }

             else if (obj.event === 'delete') {
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.modalConfirm("注：您确定要删除选择的数据吗？", function (r) {
                     if (r) {
                         var alldata = table.cache.currentTableId;
                         for (var j = 0; j < data.length; j++) {
                             for (var i = alldata.length - 1; i >= 0; i--) {
                                 if (alldata[i].F_Id == data[j].F_Id) {
                                     alldata.splice(i, 1);
                                     break;
                                 }
                             }
                         }
                         table.reload('currentTableId', { data: alldata })
                     }
                 });
             }
             return false;
         });
        function initControl() {
            //此处需修改
            //绑定数据源
            //类型为下拉框时

        }

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var postData = data.field;
             postData.list = table.cache.currentTableId;
             if (!postData.list || postData.list.length == 0) {
                 common.modalMsg("明细不能为空!");
                 return false;

             }

             if (!postData["F_EnabledMark"]) postData["F_EnabledMark"] = false;


            common.submitForm({
                 url: '/SalaryManagement/Salarytable/SubmitForm?keyValue=' + keyValue,
                param: postData,
                success: function () {
                    common.parentreload('data-search-btn');
                }
            })
            return false;
        });


    });


</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">


                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_EnCode" name="F_EnCode" autocomplete="off" lay-verify="required" placeholder="请输入" lay-filter="a" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_FullName" name="F_FullName" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">核算月</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_HeadDate" name="F_HeadDate" autocomplete="off" lay-verify="required" placeholder="请输入" lay-filter="a" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label ">备注</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_Description" name="F_Description" autocomplete="off" placeholder="请输入" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-col-md12 layui-col-sm12">


                        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container" id="toolbar">

                     <button id="NF-add" name="NF-add" class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe642;</i>核算工资</button>

                    <button id="NF-delete" name="NF-delete" class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</button>
                </div>
            </script>
        </div>
    </div>
</body>

